package jvm;

import javax.print.DocFlavor;
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;

public class TestMyClassLoader02 {
    public static void main(String[] args) throws Exception{
        File file =new File("D:\\yh\\workspace\\");
        //File to URL
        URI uri = file.toURI();
        URL[] urls = {uri.toURL()};
        ClassLoader classLoader = new MyClassLoader02(urls);
        Class<?> cls = classLoader.loadClass("pkg.Search");
        System.out.println(classLoader);
        Object obj = cls.newInstance();
        System.out.println(obj);
    }
}

class MyClassLoader02 extends URLClassLoader{

    public MyClassLoader02(URL[] urls) {
        super(urls,null); //指定父加载器为null
    }
}